package com.lwj.liwanjia.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.lwj.liwanjia.R;
import com.lwj.liwanjia.bean.WorkHomeTypeBean;
import com.lwj.liwanjia.view.activity.work.shang_jia.WoShiShangJiaActivity;

import java.util.List;

/**
 * Created by 001 on 2017/9/12.
 */

public class WorkHomeTypeAdapter extends RecyclerView.Adapter<WorkHomeTypeAdapter.ViewHolder> {

    private Context mContext;
    private List<WorkHomeTypeBean> mList;

    public WorkHomeTypeAdapter(Context mContext, List<WorkHomeTypeBean> mList) {
        this.mContext = mContext;
        this.mList = mList;

    }


    @Override
    public WorkHomeTypeAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_shape_type, parent, false);

        final ViewHolder holder = new ViewHolder(view);

        holder.iv_logo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //分类进行跳转
                byTypeToActivity(holder);
            }
        });

        return holder;
    }

    @Override
    public void onBindViewHolder(WorkHomeTypeAdapter.ViewHolder holder, int position) {

        WorkHomeTypeBean bean = mList.get(position);

        String title = bean.title;

        holder.tv_title.setText(title);

        //设置相应图标
        initLogo(title, holder);

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        ImageView iv_logo;
        TextView tv_title;

        public ViewHolder(View itemView) {
            super(itemView);

            iv_logo = (ImageView) itemView.findViewById(R.id.iv_logo);
            tv_title = (TextView) itemView.findViewById(R.id.tv_title);
        }
    }

    //设置相应图标
    private void initLogo(String title, ViewHolder holder) {

        switch (title) {
            case "我是房东":
                holder.iv_logo.setImageResource(R.mipmap.woshifangdong);
                break;
            case "我是商家":
                holder.iv_logo.setImageResource(R.mipmap.woshishangjia);
                break;
            case "我是跑腿":
                holder.iv_logo.setImageResource(R.mipmap.woshipaotui);
                break;
            case "旅游":
                holder.iv_logo.setImageResource(R.mipmap.lvyou);
                break;
            case "司机":
                holder.iv_logo.setImageResource(R.mipmap.siji);
                break;
            case "我是店家":
                holder.iv_logo.setImageResource(R.mipmap.woshidianjia);
                break;
            case "我是服务商":
                holder.iv_logo.setImageResource(R.mipmap.woshifuwu);
                break;
            case "我的笔记":
                holder.iv_logo.setImageResource(R.mipmap.wodebiji);
                break;
            case "志愿者":
                holder.iv_logo.setImageResource(R.mipmap.zhiyuanzhe);
                break;
            case "备忘录":
                holder.iv_logo.setImageResource(R.mipmap.beiwanglu);
                break;
            case "资料保存":
                holder.iv_logo.setImageResource(R.mipmap.zhiliaobaocun);
                break;
        }
    }

    //分类进行跳转
    private void byTypeToActivity(ViewHolder holder) {

        String title = holder.tv_title.getText().toString().trim();

        switch (title) {
            case "我是房东":
//                mContext.startActivity(new Intent(mContext, FangDongRegisterActivity.class));
                Toast.makeText(mContext, "暂未开通", Toast.LENGTH_SHORT).show();
                break;
            case "我是商家":
                mContext.startActivity(new Intent(mContext, WoShiShangJiaActivity.class));
                //mContext.startActivity(new Intent(mContext, RiHuaXiHuActivity.class));
                //mContext.startActivity(new Intent(mContext, RegisterActivity.class));
                break;
            case "我是跑腿":
//                mContext.startActivity(new Intent(mContext, FangDongRegisterActivity.class));
                Toast.makeText(mContext, "暂未开通", Toast.LENGTH_SHORT).show();
                break;
            case "旅游":
                Toast.makeText(mContext, "暂未开通", Toast.LENGTH_SHORT).show();
//                mContext.startActivity(new Intent(mContext, FangDongRegisterActivity.class));
                break;
            case "司机":
                Toast.makeText(mContext, "暂未开通", Toast.LENGTH_SHORT).show();
//                mContext.startActivity(new Intent(mContext, FangDongRegisterActivity.class));
                break;
            case "我是店家":
//                mContext.startActivity(new Intent(mContext, DianJiaRegisterActivity.class));
                Toast.makeText(mContext, "暂未开通", Toast.LENGTH_SHORT).show();

                break;
            case "我是服务商":
//                mContext.startActivity(new Intent(mContext, FangDongRegisterActivity.class));
                Toast.makeText(mContext, "暂未开通", Toast.LENGTH_SHORT).show();

                break;
            case "我的笔记":
//                mContext.startActivity(new Intent(mContext, BiJiHomeActivity.class));
                Toast.makeText(mContext, "暂未开通", Toast.LENGTH_SHORT).show();

                break;
            case "志愿者":
//                mContext.startActivity(new Intent(mContext, FangDongRegisterActivity.class));
                Toast.makeText(mContext, "暂未开通", Toast.LENGTH_SHORT).show();

                break;
            case "备忘录":
//                Toast.makeText(mContext, "暂未开放", Toast.LENGTH_SHORT).show();
                Toast.makeText(mContext, "暂未开通", Toast.LENGTH_SHORT).show();
                break;
            case "资料保存":
//                Toast.makeText(mContext, "暂未开放", Toast.LENGTH_SHORT).show();
                Toast.makeText(mContext, "暂未开通", Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
